home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / ajax.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  6KB  |  225 lines

  1. /***************************************************************************
  2.  
  3.   machine.c
  4.  
  5.   Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
  6.   I/O ports)
  7.  
  8. ***************************************************************************/
  9.  
  10. #include "driver.h"
  11. #include "cpu/m6809/m6809.h"
  12. #include "cpu/z80/z80.h"
  13. #include "cpu/konami/konami.h"
  14. #include "vidhrdw/konamiic.h"
  15.  
  16. unsigned char *ajax_sharedram;
  17. extern unsigned char ajax_priority;
  18. static int firq_enable;
  19.  
  20. /*    ajax_bankswitch_w:
  21.     Handled by the LS273 Octal +ve edge trigger D-type Flip-flop with Reset at H11:
  22.  
  23.     Bit    Description
  24.     ---    -----------
  25.     7    MRB3    Selects ROM N11/N12
  26.     6    CCOUNT2    Coin Counter 2    (*)
  27.     5    CCOUNT1    Coin Counter 1    (*)
  28.     4    SRESET    Slave CPU Reset?
  29.     3    PRI0    Layer Priority Selector
  30.     2    MRB2    \
  31.     1    MRB1     |    ROM Bank Select
  32.     0    MRB0    /
  33.  
  34.     (*)    The Coin Counters are handled by the Konami Custom 051550
  35. */
  36.  
  37. static WRITE_HANDLER( ajax_bankswitch_w )
  38. {
  39.     unsigned char *RAM = memory_region(REGION_CPU1);
  40.     int bankaddress = 0;
  41.  
  42.     /* rom select */
  43.     if (!(data & 0x80))    bankaddress += 0x8000;
  44.  
  45.     /* coin counters */
  46.     coin_counter_w(0,data & 0x20);
  47.     coin_counter_w(1,data & 0x40);
  48.  
  49.     /* priority */
  50.     ajax_priority = data & 0x08;
  51.  
  52.     /* bank # (ROMS N11 and N12) */
  53.     bankaddress += 0x10000 + (data & 0x07)*0x2000;
  54.     cpu_setbank(2,&RAM[bankaddress]);
  55. }
  56.  
  57. /*    ajax_lamps_w:
  58.       Handled by the LS273 Octal +ve edge trigger D-type Flip-flop with Reset at B9:
  59.  
  60.     Bit    Description
  61.     ---    -----------
  62.     7    LAMP7 & LAMP8 - Game over lamps (*)
  63.     6    LAMP3 & LAMP4 - Game over lamps (*)
  64.     5    LAMP1 - Start lamp (*)
  65.     4    Control panel quaking (**)
  66.     3    Joystick vibration (**)
  67.     2    LAMP5 & LAMP6 - Power up lamps (*)
  68.     1    LAMP2 - Super weapon lamp (*)
  69.     0    unused
  70.  
  71.     (*) The Lamps are handled by the M54585P
  72.     (**)Vibration/Quaking handled by these chips:
  73.         Chip        Location    Description
  74.         ----        --------    -----------
  75.         PS2401-4    B21            ???
  76.         UPA1452H    B22            ???
  77.         LS74        H2            Dual +ve edge trigger D-type Flip-flop with SET and RESET
  78.         LS393        C20            Dual -ve edge trigger 4-bit Binary Ripple Counter with Resets
  79. */
  80.  
  81. static WRITE_HANDLER( ajax_lamps_w )
  82. {
  83.     osd_led_w(0,(data & 0x02) >> 1);    /* super weapon lamp */
  84.     osd_led_w(1,(data & 0x04) >> 2);    /* power up lamps */
  85.     osd_led_w(5,(data & 0x04) >> 2);    /* power up lamps */
  86.     osd_led_w(2,(data & 0x20) >> 5);    /* start lamp */
  87.     osd_led_w(3,(data & 0x40) >> 6);    /* game over lamps */
  88.     osd_led_w(6,(data & 0x40) >> 6);    /* game over lamps */
  89.     osd_led_w(4,(data & 0x80) >> 7);    /* game over lamps */
  90.     osd_led_w(7,(data & 0x80) >> 7);    /* game over lamps */
  91. }
  92.  
  93. /*    ajax_ls138_f10:
  94.     The LS138 1-of-8 Decoder/Demultiplexer at F10 selects what to do:
  95.  
  96.     Address    R/W    Description
  97.     -------    ---    -----------
  98.     0x0000    (r)    ???    I think this read is because a CPU core bug
  99.             (w)    0x0000    NSFIRQ    Trigger FIRQ on the M6809
  100.                 0x0020    AFR        Watchdog reset (handled by the 051550)
  101.     0x0040    (w)    SOUND            Cause interrupt on the Z80
  102.     0x0080    (w)    SOUNDDATA        Sound code number
  103.     0x00c0    (w) MBL1            Enables the LS273 at H11 (Banking + Coin counters)
  104.     0x0100    (r) MBL2            Enables 2P Inputs reading
  105.     0x0140    (w) MBL3            Enables the LS273 at B9 (Lamps + Vibration)
  106.     0x0180    (r) MIO1            Enables 1P Inputs + DIPSW #1 & #2 reading
  107.     0x01c0    (r) MIO2            Enables DIPSW #3 reading
  108. */
  109.  
  110. READ_HANDLER( ajax_ls138_f10_r )
  111. {
  112.     int data = 0;
  113.  
  114.     switch ((offset & 0x01c0) >> 6){
  115.         case 0x00:    /* ??? */
  116.             data = rand();
  117.             break;
  118.         case 0x04:    /* 2P inputs */
  119.             data = readinputport(5);
  120.             break;
  121.         case 0x06:    /* 1P inputs + DIPSW #1 & #2 */
  122.             if (offset & 0x02)
  123.                 data = readinputport(offset & 0x01);
  124.             else
  125.                 data = readinputport(3 + (offset & 0x01));
  126.             break;
  127.         case 0x07:    /* DIPSW #3 */
  128.             data = readinputport(2);
  129.             break;
  130.  
  131.         default:
  132.             logerror("%04x: (ls138_f10) read from an unknown address %02x\n",cpu_get_pc(), offset);
  133.     }
  134.  
  135.     return data;
  136. }
  137.  
  138. WRITE_HANDLER( ajax_ls138_f10_w )
  139. {
  140.     switch ((offset & 0x01c0) >> 6){
  141.         case 0x00:    /* NSFIRQ + AFR */
  142.             if (offset)
  143.                 watchdog_reset_w(0, data);
  144.             else{
  145.                 if (firq_enable)    /* Cause interrupt on slave CPU */
  146.                     cpu_cause_interrupt(1,M6809_INT_FIRQ);
  147.             }
  148.             break;
  149.         case 0x01:    /* Cause interrupt on audio CPU */
  150.             cpu_cause_interrupt(2,Z80_IRQ_INT);
  151.             break;
  152.         case 0x02:    /* Sound command number */
  153.             soundlatch_w(offset,data);
  154.             break;
  155.         case 0x03:    /* Bankswitch + coin counters + priority*/
  156.             ajax_bankswitch_w(0, data);
  157.             break;
  158.         case 0x05:    /* Lamps + Joystick vibration + Control panel quaking */
  159.             ajax_lamps_w(0, data);
  160.             break;
  161.  
  162.         default:
  163.             logerror("%04x: (ls138_f10) write %02x to an unknown address %02x\n",cpu_get_pc(), data, offset);
  164.     }
  165. }
  166.  
  167. /* Shared RAM between the 052001 and the 6809 (6264SL at I8) */
  168. READ_HANDLER( ajax_sharedram_r )
  169. {
  170.     return ajax_sharedram[offset];
  171. }
  172.  
  173. WRITE_HANDLER( ajax_sharedram_w )
  174. {
  175.     ajax_sharedram[offset] = data;
  176. }
  177.  
  178. /*    ajax_bankswitch_w_2:
  179.     Handled by the LS273 Octal +ve edge trigger D-type Flip-flop with Reset at K14:
  180.  
  181.     Bit    Description
  182.     ---    -----------
  183.     7    unused
  184.     6    RMRD    Enable char ROM reading through the video RAM
  185.     5    RVO        enables 051316 wraparound
  186.     4    FIRQST    FIRQ control
  187.     3    SRB3    \
  188.     2    SRB2     |
  189.     1    SRB1     |    ROM Bank Select
  190.     0    SRB0    /
  191. */
  192.  
  193. WRITE_HANDLER( ajax_bankswitch_2_w )
  194. {
  195.     unsigned char *RAM = memory_region(REGION_CPU2);
  196.     int bankaddress;
  197.  
  198.     /* enable char ROM reading through the video RAM */
  199.     K052109_set_RMRD_line((data & 0x40) ? ASSERT_LINE : CLEAR_LINE);
  200.  
  201.     /* bit 5 enables 051316 wraparound */
  202.     K051316_wraparound_enable(0, data & 0x20);
  203.  
  204.     /* FIRQ control */
  205.     firq_enable = data & 0x10;
  206.  
  207.     /* bank # (ROMS G16 and I16) */
  208.     bankaddress = 0x10000 + (data & 0x0f)*0x2000;
  209.     cpu_setbank(1,&RAM[bankaddress]);
  210. }
  211.  
  212.  
  213. void ajax_init_machine( void )
  214. {
  215.     firq_enable = 1;
  216. }
  217.  
  218. int ajax_interrupt( void )
  219. {
  220.     if (K051960_is_IRQ_enabled())
  221.         return KONAMI_INT_IRQ;
  222.     else
  223.         return ignore_interrupt();
  224. }
  225.